home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
13316
/
13316.xpi
/
content
/
openPageDialog.js
< prev
next >
Wrap
Text File
|
2009-10-01
|
8KB
|
221 lines
/* Copyright (C) 2009 Norman Solomon
* e-mail: historytree.addon@yahoo.com
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*/
// *************************************************************************
// ***** *****
// ***** MODAL DIALOG OPENED FROM "historyViewer.js" *****
// ***** -------------------------------------------------------- *****
// ***** Goes to or opens TV or GV page that user clicks on via a *****
// ***** chain of "historyViewer.js" > "firefoxOverlay.js" methods *****
// ***** *****
// *************************************************************************
// Global used by this window
var gOKbtnClick = false;
// ========================================================
// Window onLoad event listener, and associated function
// ========================================================
window.addEventListener("load", onLoad, false);
function onLoad()
{
try
{
// Get references to this window's GUI controls
var menuSelTab = document.getElementById("menuSelTab");
var optGrpOpen = document.getElementById("optGrpOpen");
var optCurrTab = document.getElementById("optCurrTab");
var optSelTab = document.getElementById("optSelTab");
var optGoto = document.getElementById("optGoto");
var lblPageDesc = document.getElementById("lblPageDesc");
var lblPageURL = document.getElementById("lblPageURL");
// Init other vars
var parentWin = window.opener; // "historyViewer.xul"
var tNode; // HistoryNode
var truncDesc, truncURL; // Strings
// Get data that was put into App Storage by this window's opener
tNode = Application.storage.get("openPageTreeNode", null);
// --------------------------------------------------------------
// Show centralised, truncated web-page description in <label...>
parentWin.gCtx.mozTextStyle = "bold 7pt verdana";
truncDesc = parentWin.truncatedText(tNode.histNode.desc, 200);
lblPageDesc.value = truncDesc;
// Show centralised, truncated web-page URL in <label...>
parentWin.gCtx.mozTextStyle = "7pt verdana";
truncURL = parentWin.truncatedText(tNode.histNode.uri, 200);
lblPageURL.value = truncURL;
// Initialize GUI depending on type of page user clicked on
if (parentWin.numExtWinOpenTabs() > 0)
{
// Fill <menulist...> with Tab root page descriptions
fillMenulistWithTabRootDescriptions();
// Set default <radio...> option
if (tNode.isOpenPage)
{
// Default option is "Go to history page"
optGrpOpen.selectedIndex = 0;
}
else
{
// Default option is "Open page in current Tab"
optGrpOpen.selectedIndex = 1;
// Disable "Goto page" option (can't goto closed page)
optGoto.disabled = true;
}
}
else
{
// Only possible option is "Open page in a new tab"
optGrpOpen.selectedIndex = 2;
// Disable other <radio...>'s and <menulist...>
optGoto.disabled = true;
optCurrTab.disabled = true;
optSelTab.disabled = true;
menuSelTab.disabled = true;
}
}
catch (e)
{
alert("History Tree Extension - Modal window load error");
}
}
// ============================================================
// Extension window onFocus listener and associated function
// ============================================================
window.addEventListener("focus", onFocus, false);
function onFocus()
{
// Get window size - As automatically set by the XUL renderer
var winHgt = this.outerHeight + 15;
var winWid = this.outerWidth;
if (winWid < 265)
winWid = 265;
// Make sure window has a border round the edges
this.resizeTo(winWid, winHgt);
}
// ================================================================
// Called from "openPageDialog.xul" <button "btnOK"...> onclick()
// ================================================================
function okButtonEventHandler(event)
{
// Close this window and Goto/open history page
gOKbtnClick = true;
this.close();
}
// ====================================================================
// Called from "openPageDialog.xul" <button "btnCancel"...> onclick()
// ====================================================================
function cancelButtonEventHandler(event)
{
// Close this window but DO NOT goto/open history page
gOKbtnClick = false;
this.close();
}
// ======================================================
// Called when this window is closed via JS this.close()
// ======================================================
window.addEventListener("unload", onUnload, false);
function onUnload()
{
// Goto/open page if user clicked on the "OK" button
if (gOKbtnClick)
{
// Get this window's GUI control attributes
var parentWin = window.opener; // "historyViewer.xul"
var optGrpOpen = document.getElementById("optGrpOpen");
var optNum = optGrpOpen.selectedIndex;
var menuSelTab = document.getElementById("menuSelTab");
var selTabID;
// Get selected <menulist...> row if its available *** NOTE
// selTabID is ONLY used for "Open page in tab selected" option
if (!menuSelTab.disabled)
selTabID = menuSelTab.selectedItem.value;
else
selTabID = "";
// Call "historyViewer.js" method, passing in user's GUI options
// *** NOTE - This method immediately switches focus to FF win
parentWin.showHistoryPageInFirefox(optNum, selTabID);
}
}
// ========================================================
// Window onBlur (lost focus) event listener, and function
// ========================================================
window.addEventListener("blur", onLostFocus, false);
function onLostFocus()
{
// Set flag that causes exit from parent window's onFocus()
window.opener.gExitWinFocusEvent = true;
window.opener.focus();
// close() ensures that parentWin onFocus() updates occur
this.close();
}
// ====================================================
// Fills <menulist...> with Tab root page descriptions
// ====================================================
function fillMenulistWithTabRootDescriptions()
{
// Init vars
var parentWin = window.opener;
var menuSelTab = document.getElementById("menuSelTab");
var menuItem;
var listItemTxt;
var tabRoot;
// --------------------------------------------------
// Fill the <menulist...> with Tab root descriptions
for (var i = 0; i < parentWin.gTabRoots.length; i++)
{
// Get Tab root TreeNode object
tabRoot = parentWin.gTabRoots[i];
// Add <menulist...> menuitem if Tab is open
if (tabRoot.inOpenTab)
{
// Set <menulist...> item prefix
listItemTxt = (i + 1).toString() + " - ";
// Add web-page description from Tab root HistoryNode
listItemTxt += tabRoot.histNode.desc;
// Add menuitem to <menulist...> including tabID as item.value
menuSelTab.appendItem(listItemTxt, tabRoot.histNode.tab);
// Set style attributes for added menuItem
menuItem = menuSelTab.getItemAtIndex(i);
menuItem.style.fontFamily = "Verdana";
menuItem.style.fontSize = "7pt";
menuItem.style.fontWeight = "bold";
}
}
// Select the first <menulist...> row
menuSelTab.selectedIndex = 0;
}